<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../layui/layui.all.js"  media="all">
</head>
<body>
<!--表单-->

<!--添加缺陷类型-->

<form id="defect_table" class="layui-form" method="" action="" style="margin-top: 30px">

    <!--第一个-->
    <div style="float: left;">

        <div class="layui-form-item" >
            <label class="layui-form-label">任务编号：</label>
            <div class="layui-input-inline">
                <input type="text" id="task_id" name="task_id"   lay-verify="required|task_id" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
                </input>
            </div>
            <label class="layui-form-label">线路编号：</label>
            <div class="layui-input-inline">
                <input type="text" id="line_id" name="line_id"   lay-verify="required|line_id" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
             </input>
            </div>
            <label class="layui-form-label">杆塔编号：</label>
            <div class="layui-input-inline">
                <input type="text" id="tower_id" name="tower_id"   lay-verify="required|tower_id" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
                </input>
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label">缺陷类型：</label>
            <div class="layui-input-inline">
                <input type="text" id="defect_name" name="defect_name"   lay-verify="required|defect_name" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
                </input>
            </div>
            <label class="layui-form-label">完好率：</label>
            <div class="layui-input-inline">
                <input type="text" id="intact" name="intact"   lay-verify="required|intact" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
             </input>
            </div>
            <label class="layui-form-label">缺陷描述：</label>
            <div class="layui-input-inline">
                <input type="text" id="defect_des" name="defect_des"   lay-verify="required|defect_des" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
                </input>
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label">发现时间：</label>
            <div class="layui-input-inline">
                <input type="text" id="find_time" name="find_time"   lay-verify="required|find_time" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
            </div>
            <label class="layui-form-label">发现人员：</label>
            <div class="layui-input-inline">
                <input type="text" id="user_name" name="user_name"   lay-verify="required|user_name" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
            </div>
        </div>

    </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缺陷级别：</label>
        <div class="layui-input-inline" style="width: 530px">
            <input type="radio" name="defect_grade_name" value="1" title="一般" checked>
            <input type="radio" name="defect_grade_name" value="2" title="紧急">
            <input type="radio" name="defect_grade_name" value="3" title="严重">
        </div>

    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="formDemo2" lay-filter="formDemo2" style="margin-left: 350px" >确认</button>

        </div>
    </div>
</form>
<script src="../layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','table','laydate','layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,laydate = layui.laydate
            ,layedit = layui.layedit
            , form = layui.form
            ,layer=layui.layer
            ,table=layui.table;

        form.on('submit(formDemo2)', function(data){
            console.log(data.field.defect_grade_name);
            var task_id=data.field.task_id;
            var defect_grade_name=data.field.defect_grade_name;
            if (defect_grade_name==1){
                defect_grade_name="1";
                console.log(defect_grade_name);

            }else if (defect_grade_name==2){
                defect_grade_name="2";
                console.log(defect_grade_name);
            }else{
                defect_grade_name="3";
                console.log(defect_grade_name);
            }
        $.ajax({
            url:"/updategrade",
            async: false,
            type:"POST",
            dataType: "json",
            data:{task_id:task_id,defect_grade_name:defect_grade_name},
            success:function (res) {
                if (res.code == 200 ){
                    parent.layer.close(parent.layer.index);
                    clearInterval(interval);
                    layer.msg(res.msg,{icon:1,time:2000});
                    var second=1;
                    //定时器2秒后跳转
                    var interval = setInterval(function () {
                        second--;
                        if (second === -1) {
                            parent.layer.close(parent.layer.index);
                            clearInterval(interval);
                        }
                    }, 1000);
                }else if (res.code==500){
                    layer.msg(res.msg,{icon:5});
                }else if (res.code == 405){
                    layer.msg(res.msg,{icon:5});
                }
            }

        });
    });
        function close() {
            close();
        }
    });
</script>
</body>
</html>